<template>
  <div class="ever-note-wrap">
    <div class="handle-wrap">
      <div>我的笔记</div>
      <div>
        <el-link :underline="false" type="primary" @click="writeNotes"
          >写笔记</el-link
        >
      </div>
    </div>
    <div class="divider"></div>
    <div class="main-notes">
      <div v-if="noteList.length>0">
        <div class="notes"  v-for="(note, index) in noteList" :key="index" @click.stop="seenNoteDetail(note)" >
        <h4 class="header">{{ note.title }}</h4>
        <div class="footer">
          <!-- <el-link
            type="primary"
            :underline="false"
            style="margin-right: 10px"
            >{{ note.updated_time }}</el-link
          > -->
          <el-link
            type="primary"
            style="margin-right: 10px"
            @click.stop="editor(note)"
            >修改</el-link
          >
          <el-link type="danger" @click.stop="remove(note)">删除</el-link>
        </div>
      </div>
      </div>
      <div class="no-data" v-else>
           <img src="~src/assets/noData.png" alt="">
           <div class="no-data-footer-text">暂无数据</div>
      </div>
    </div>
  </div>
</template>

<script>
import request from "utils/request";
import { ElMessage, ElMessageBox } from "element-plus";
export default {
  name: "JddChromePluginsEverNote",

  data() {
    return {
      noteList: [],
    };
  },

  mounted() {
    this.getNoteList();
  },

  methods: {
    writeNotes() {
      this.$router.push({
        path: "/write-notes",
      });
    },
    seenNoteDetail(note){
      this.$router.push({
        path: "/note-detail",
        query: {
          id: note.id,
        },
      });
    },
    async getNoteList() {
      let ret = await request.get("/selfNoteList");
      if (ret.data) {
        this.noteList = ret.data;
      }
    },
    async remove(note) {
      ElMessageBox.confirm("确认需要删除该笔记?", "警告", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          let ret = await request.post("/deleteNote", {
            id: note.id,
          });
          if (ret.code == 200) {
            this.$message({
              message: "移除成功",
              type: "success",
            });
            this.getNoteList();
          } else {
            this.$message({
              message: ret.message,
              type: "error",
            });
          }
        })
        .catch(() => {
          ElMessage({
            type: "info",
            message: "取消删除",
          });
        });
    },
    async editor(note) {
      this.$router.push({
        path: "/write-notes",
        query: {
          id: note.id,
        },
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.ever-note-wrap {
  .handle-wrap {
    display: flex;
    line-height: 34px;
    justify-content: space-between;
    padding: 0 12px;
  }
  .divider {
    width: 100%;
    height: 1px;
    background: #dcdfe6;
  }
  .main-notes {
    padding: 0px 8px;
  }
  .notes {
    padding: 12px 15px;
    margin: 8px 0px;
    box-shadow: 0px 0px 12px rgba(0, 0, 0, 0.12);
    border-radius: 5px;
    cursor: pointer;
    .header {
      line-height: 30px;
    }
    .footer {
      display: flex;
      justify-content: flex-end;
    }
  }
  .no-data{
    text-align: center;
    padding: 80px 0px 10px;
    .no-data-footer-text{
      line-height: 32px;
      font-size: 13px;
      margin-top: 5px;
      color: #aeaeae;
    }
  }
}
</style>
